<template>
	<view>
		<view class="formlist">
			<form @submit="save">
				<view class="ln"><input name="names" :value="names" placeholder="输入工程名称" /></view>
				<picker mode="date" :value="btm" @change="selbtm">
					<view>{{btm}}</view>
				</picker>
				<button form-type="submit">保存</button>				
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:0,
				names:"", //工程名称
				btm:"输入工程时间", //开始时间
			}
		},
		onLoad(opt){
			this.id = opt.id;
			if(this.id){
				uni.setNavigationBarTitle({title:"修改工程"});
				let self = this;
				uni.request({
					url:this.apibase + "gcdetail?id=" + this.id,
					success: (res) => {
						self.names = res.data.names;
						self.btm = res.data.btm||"输入工程时间"
					}
				});
			}else{
				uni.setNavigationBarTitle({title:"添加工程"});
			}
		},
		methods: {
			selbtm(val){
				this.btm = val.detail.value;
			},
			save(e){
				let self = this, pd = e.detail.value;
				pd.btm = this.btm;
				uni.request({
					url:this.apibase + (this.id?"gcedit?id="+this.id:"gcadd"),
					method:"POST",
					data:pd,
					success: (res) => {
						uni.showToast({
							title:"操作成功",
							success:()=>{
								uni.navigateBack({
									animationDuration:500
								})
							}
						})
						//console.log(res.data);
					}
				});
			}
		}
	}
</script>

<style>

</style>
